package com.yc.vcode;

import com.yc.vcode.bean.VcodeProperties;
import com.yc.vcode.web.VcodeInterceptor;
import com.yc.vcode.web.VcodeInterceptor1;
import com.yc.vcode.web.VcodeInterceptor2;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@AutoConfiguration
@ComponentScan("com.yc.vcode")
@ConditionalOnProperty(prefix = "vcode", name = "enable", havingValue = "true")
@Slf4j
public class VcodeConfig implements WebMvcConfigurer {

    @Autowired
    VcodeProperties properties;

    //注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //没有注入bean
        registry.addInterceptor(new VcodeInterceptor())
                .addPathPatterns(properties.getPaths());

        registry.addInterceptor(new VcodeInterceptor1())
                .addPathPatterns("/reg");

        registry.addInterceptor(new VcodeInterceptor2())
                .addPathPatterns("/pwdemail");
    }

}
